package com.itheima;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/loginservlet")
public class loginservlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取用户民,密码
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        //判断用户名是否为空
        if(username==null||"".equals(username)){
            resp.sendRedirect("/stu/login.jsp");
            return;
        }
        //不为空,存入会话域中
        req.getSession().setAttribute("username",username);
        //重定向到首页
        resp.sendRedirect("/stu/index.jsp");


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
